package com.hclc.service.impl;

import com.hclc.api.job.IJobAndTriggerService;
import com.hclc.entity.model.enums.QuartzEnums;
import com.hclc.service.QuartzWrapperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * 封装了一下lx的定时任务
 * @创建人 ws
 * @郵箱 zhisirudan@gmail.com
 * @创建时间 2019/11/10
 */
@Service
public class QuartzWrapperServiceImpl implements QuartzWrapperService {
    @Autowired
    private IJobAndTriggerService jobAndTriggerService;

    @Override
    public void getJobList(QuartzEnums quartzEnums) throws Exception {

    }

    @Override
    public void addJob(QuartzEnums quartzEnums, String cron, long userId) throws Exception {
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        addJob(quartzEnums, cron, userId, objectObjectHashMap);
    }

    @Override
    public void addJob(QuartzEnums quartzEnums, String cron, long userId, Map map) throws Exception {
        LocalDateTime now = LocalDateTime.now();
        String jobClassName = quartzEnums.getPackageClass();
        String jobGroupName = quartzEnums.name() + "_" + userId + "_" + now.toString();
        String cronExpression = cron;
        String jobDescription = quartzEnums.getDesc();
        jobAndTriggerService.addJob(jobClassName, jobGroupName, cronExpression, jobDescription, map);
    }

}
